home *** CD-ROM | disk | FTP | other *** search
/ Enter 2004 April / enter-2004-04.iso / files / httrack-3.30.exe / {app} / src / htslib.h < prev    next >
Encoding:
C/C++ Source or Header  |  2003-10-11  |  14.1 KB  |  379 lines

  1. /* ------------------------------------------------------------ */
  2. /*
  3. HTTrack Website Copier, Offline Browser for Windows and Unix
  4. Copyright (C) Xavier Roche and other contributors
  5.  
  6. This program is free software; you can redistribute it and/or
  7. modify it under the terms of the GNU General Public License
  8. as published by the Free Software Foundation; either version 2
  9. of the License, or any later version.
  10.  
  11. This program is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with this program; if not, write to the Free Software
  18. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  19.  
  20.  
  21. Important notes:
  22.  
  23. - We hereby ask people using this source NOT to use it in purpose of grabbing
  24. emails addresses, or collecting any other private information on persons.
  25. This would disgrace our work, and spoil the many hours we spent on it.
  26.  
  27.  
  28. Please visit our Website: http://www.httrack.com
  29. */
  30.  
  31.  
  32. /* ------------------------------------------------------------ */
  33. /* File: Subroutines .h                                         */
  34. /* Author: Xavier Roche                                         */
  35. /* ------------------------------------------------------------ */
  36.  
  37. // Fichier librairie .h
  38.  
  39. #ifndef HTS_DEFH
  40. #define HTS_DEFH 
  41.  
  42. /* dΘfinitions globales */
  43. #include "htsglobal.h"
  44.  
  45. /* basic net definitions */
  46. #include "htsbasenet.h"
  47.  
  48. /* cookies et auth */
  49. #include "htsbauth.h"
  50.  
  51. // Attention, dΘfinition existante Θgalement dans le shell
  52. // (α modifier avec celle-ci)
  53. #define POSTTOK "?>post"
  54.  
  55. #include <stdio.h>
  56.  
  57. #include "htsopt.h"
  58.  
  59. // structure pour paramΦtres supplΘmentaires lors de la requΩte
  60. typedef struct {
  61.   short int user_agent_send;  // user agent (ex: httrack/1.0 [sun])
  62.   short int http11;           // l'en tΩte peut (doit) Ωtre signΘ HTTP/1.1 et non HTTP/1.0
  63.   short int nokeepalive;      // pas de keep-alive
  64.   short int range_used;       // Range utilisΘ
  65.   short int nocompression;    // Pas de compression
  66.   short int flush_garbage;    // recycled
  67.   char user_agent[128];
  68.   char lang_iso[64];
  69.   t_proxy proxy;              // proxy
  70. } htsrequest;
  71.  
  72.  
  73. // structure pour retour d'une connexion/prise d'en tΩte
  74. typedef struct {
  75.   int statuscode;        // status-code, -1=erreur, 200=OK,201=..etc (cf RFC1945)
  76.   short int notmodified; // page ou fichier NON modifiΘ (transfΘrΘ)
  77.   short int is_write;    // sortie sur disque (out) ou en mΘmoire (adr)
  78.   short int is_chunk;    // mode chunk
  79.   short int compressed;  // compressΘ?
  80.   short int empty;       // vide?
  81.   short int keep_alive;  // Keep-Alive?
  82.   short int keep_alive_trailers;  // ..with trailers extension
  83.   int keep_alive_t;      // KA timeout
  84.   int keep_alive_max;    // KA number of requests
  85.   char* adr;             // adresse du bloc de mΘmoire, NULL=vide
  86.   FILE* out;             // Θcriture directe sur disque (si is_write=1)
  87.   LLint size;            // taille fichier
  88.   char msg[80];          // message Θventuel si Θchec ("\0"=non prΘcisΘ)
  89.   char contenttype[64];  // content-type ("text/html" par exemple)
  90.   char charset[64];      // charset ("iso-8859-1" par exemple)
  91.   char contentencoding[64];  // content-encoding ("gzip" par exemple)
  92.   char* location;        // on copie dedans Θventuellement la vΘritable 'location'
  93.   LLint totalsize;       // taille totale α tΘlΘcharger (-1=inconnue)
  94.   short int is_file;     // ce n'est pas une socket mais un descripteur de fichier si 1
  95.   T_SOC soc;             // ID socket
  96.   FILE* fp;              // fichier pour file://
  97. #if HTS_USEOPENSSL
  98.   short int ssl;         // is this connection a SSL one? (https)
  99.   // BIO* ssl_soc;          // SSL structure
  100.   SSL * ssl_con;         // connection structure
  101. #endif
  102.   char lastmodified[64]; // Last-Modified
  103.   char etag[64];         // Etag
  104.   char cdispo[256];      // Content-Disposition coupΘ
  105.   LLint  crange;         // Content-Range
  106.   int debugid;           // debug connection
  107.   /* */
  108.   htsrequest req;  // paramΦtres pour la requΩte
  109.   /*char digest[32+2];  // digest md5 gΘnΘrΘ par le moteur ("" si non gΘnΘrΘ)*/
  110. } htsblk;
  111.  
  112.  
  113. /* ANCIENNE STURCTURE pour cache 1.0 */
  114. typedef struct {
  115.   int statuscode;  // ANCIENNE STURCTURE - status-code, -1=erreur, 200=OK,201=..etc (cf RFC1945)
  116.   int notmodified; // ANCIENNE STURCTURE - page ou fichier NON modifiΘ (transfΘrΘ)
  117.   int is_write;    // ANCIENNE STURCTURE - sortie sur disque (out) ou en mΘmoire (adr)
  118.   char* adr;       // ANCIENNE STURCTURE - adresse du bloc de mΘmoire, NULL=vide
  119.   FILE* out;       // ANCIENNE STURCTURE - Θcriture directe sur disque (si is_write=1)
  120.   int size;        // ANCIENNE STURCTURE - taille fichier
  121.   char msg[80];    // ANCIENNE STURCTURE - message Θventuel si Θchec ("\0"=non prΘcisΘ)
  122.   char contenttype[64];  // ANCIENNE STURCTURE - content-type ("text/html" par exemple)
  123.   char* location;  // ANCIENNE STURCTURE - on copie dedans Θventuellement la vΘritable 'location'
  124.   int totalsize;   // ANCIENNE STURCTURE - taille totale α tΘlΘcharger (-1=inconnue)
  125.   int is_file;     // ANCIENNE STURCTURE - ce n'est pas une socket mais un descripteur de fichier si 1
  126.   T_SOC soc;       // ANCIENNE STURCTURE - ID socket
  127.   FILE* fp;        // ANCIENNE STURCTURE - fichier pour file://
  128.   t_proxy proxy;   // ANCIENNE STURCTURE - proxy
  129.   int user_agent_send;  // ANCIENNE STURCTURE - user agent (ex: httrack/1.0 [sun])
  130.   char user_agent[64];
  131.   int http11;           // ANCIENNE STURCTURE - l'en tΩte doit Ωtre signΘ HTTP/1.1 et non HTTP/1.0
  132. } OLD_htsblk;
  133. /* fin ANCIENNE STURCTURE pour cache 1.0 */
  134.  
  135. // cache pour le dns, pour Θviter de faire des gethostbyname sans arrΩt
  136. typedef struct t_dnscache {
  137.   char iadr[1024];
  138.   struct t_dnscache* n;
  139.   char host_addr[HTS_MAXADDRLEN];    // 4 octets (v4), ou 16 octets (v6)
  140.   int host_length;                   // 4 normalement - ==0  alors en cours de rΘsolution
  141.                                      // ou >16 si sockaddr
  142.                                      //                 ==-1 alors erreur (host n'Θxiste pas)
  143. } t_dnscache;
  144.  
  145.  
  146.  
  147.  
  148. /*
  149. #ifdef __cplusplus
  150. extern "C" {
  151. #endif
  152. */
  153.  
  154. // fonctions unix/winsock
  155. int hts_read(htsblk* r,char* buff,int size);
  156. //int HTS_TOTAL_RECV_CHECK(int var);
  157. LLint check_downloadable_bytes(int rate);
  158.  
  159. #ifndef HTTRACK_DEFLIB
  160. HTSEXT_API int hts_init(void);
  161. HTSEXT_API int hts_uninit(void);
  162. #endif
  163.  
  164. // fonctions principales
  165. int http_fopen(char* adr,char* fil,htsblk* retour);
  166. int http_xfopen(int mode,int treat,int waitconnect,char* xsend,char* adr,char* fil,htsblk* retour);
  167. int http_sendhead(t_cookie* cookie,int mode,char* xsend,char* adr,char* fil,char* referer_adr,char* referer_fil,htsblk* retour);
  168. htsblk httpget(char* url);
  169. //int newhttp(char* iadr,char* err=NULL);
  170. int newhttp(char* iadr,htsblk* retour,int port,int waitconnect);
  171. HTS_INLINE void deletehttp(htsblk* r);
  172. HTS_INLINE int  deleteaddr(htsblk* r);
  173. HTS_INLINE void deletesoc(T_SOC soc);
  174. HTS_INLINE void deletesoc_r(htsblk* r);
  175. htsblk http_location(char* adr,char* fil,char* loc);
  176. htsblk http_test(char* adr,char* fil,char* loc);
  177. int check_readinput(htsblk* r);
  178. int check_readinput_t(T_SOC soc, int timeout);
  179. void http_fread(T_SOC soc,htsblk* retour);
  180. LLint http_fread1(htsblk* r);
  181. void treathead(t_cookie* cookie,char* adr,char* fil,htsblk* retour,char* rcvd);
  182. void treatfirstline(htsblk* retour,char* rcvd);
  183. #ifndef HTTRACK_DEFLIB
  184. HTSEXT_API void infostatuscode(char* msg,int statuscode);
  185. #endif
  186.  
  187. // sous-fonctions
  188. htsblk xhttpget(char* adr,char* fil);
  189. htsblk http_gethead(char* adr,char* fil);
  190. LLint http_xfread1(htsblk* r,int bufl);
  191. HTS_INLINE t_hostent* hts_gethostbyname(char* iadr, void* v_buffer);
  192. #ifndef HTTRACK_DEFLIB
  193. HTSEXT_API t_hostent* vxgethostbyname(char* hostname, void* v_buffer);
  194. #endif
  195. t_hostent* _hts_ghbn(t_dnscache* cache,char* iadr,t_hostent* retour);
  196. int ftp_available(void);
  197. #if HTS_DNSCACHE
  198. void hts_cache_free(t_dnscache* cache);
  199. int hts_dnstest(char* _iadr);
  200. t_dnscache* _hts_cache(void);
  201. int _hts_lockdns(int i);
  202. #endif
  203.  
  204. // outils divers
  205. HTS_INLINE TStamp time_local(void);
  206. #ifndef HTTRACK_DEFLIB
  207. HTSEXT_API HTS_INLINE TStamp mtime_local(void);
  208. #endif
  209. void sec2str(char *s,TStamp t);
  210. #ifndef HTTRACK_DEFLIB
  211. HTSEXT_API void qsec2str(char *st,TStamp t);
  212. #endif
  213. void time_gmt_rfc822(char* s);
  214. void time_local_rfc822(char* s);
  215. struct tm* convert_time_rfc822(char* s);
  216. int set_filetime(char* file,struct tm* tm_time);
  217. int set_filetime_rfc822(char* file,char* date);
  218. HTS_INLINE void time_rfc822(char* s,struct tm * A);
  219. HTS_INLINE void time_rfc822_local(char* s,struct tm * A);
  220. #ifndef HTTRACK_DEFLIB
  221. HTSEXT_API char* int2char(int n);
  222. HTSEXT_API char* int2bytes(LLint n);
  223. HTSEXT_API char* int2bytessec(long int n);
  224. HTSEXT_API char** int2bytes2(LLint n);
  225. #endif
  226. HTS_INLINE int sendc(htsblk* r, char* s);
  227. int finput(int fd,char* s,int max);
  228. int binput(char* buff,char* s,int max);
  229. int linput(FILE* fp,char* s,int max);
  230. int linputsoc(T_SOC soc, char* s, int max);
  231. int linputsoc_t(T_SOC soc, char* s, int max, int timeout);
  232. int linput_trim(FILE* fp,char* s,int max);
  233. int linput_cpp(FILE* fp,char* s,int max);
  234. void rawlinput(FILE* fp,char* s,int max);
  235. int strfield(const char* f,const char* s);
  236. #define strfield2(f,s) ( (strlen(f)!=strlen(s)) ? 0 : (strfield(f,s)) )
  237. char* strstrcase(char *s,char *o);
  238. int ident_url_absolute(char* url,char* adr,char* fil);
  239. void fil_simplifie(char* f);
  240. int is_unicode_utf8(unsigned char* buffer, unsigned int size);
  241. void map_characters(unsigned char* buffer, unsigned int size, unsigned int* map);
  242. int ishtml(char* urlfil);
  243. int ishtml_ext(char* a);
  244. int ishttperror(int err);
  245. void guess_httptype(char *s,char *fil);
  246. void get_httptype(char *s,char *fil,int flag);
  247. int get_userhttptype(int setdefs,char *s,char *ext);
  248. void give_mimext(char *s,char *st);
  249. int is_knowntype(char *fil);
  250. int is_userknowntype(char *fil);
  251. int is_dyntype(char *fil);
  252. char* get_ext(char *fil);
  253. int may_unknown(char* st);
  254. #ifndef HTTRACK_DEFLIB
  255. HTSEXT_API char* jump_identification(char*);
  256. HTSEXT_API char* jump_normalized(char*);
  257. HTSEXT_API char* jump_toport(char*);
  258. HTSEXT_API char* fil_normalized(char* source, char* dest);
  259. HTSEXT_API char* adr_normalized(char* source, char* dest);
  260. #endif
  261. char* strrchr_limit(char* s, char c, char* limit);
  262. HTS_INLINE char* jump_protocol(char* source);
  263. void code64(unsigned char* a,int size_a,unsigned char* b,int crlf);
  264. #ifndef HTTRACK_DEFLIB
  265. HTSEXT_API void unescape_amp(char* s);
  266. HTSEXT_API void escape_spc_url(char* s);
  267. HTSEXT_API void escape_in_url(char* s);
  268. HTSEXT_API void escape_uri(char* s);
  269. HTSEXT_API void escape_uri_utf(char* s);
  270. HTSEXT_API void escape_check_url(char* s);
  271. HTSEXT_API char* escape_check_url_addr(char* s);
  272. HTSEXT_API void x_escape_http(char* s,int mode);
  273. HTSEXT_API void escape_remove_control(char* s);
  274. #endif
  275. int ehexh(char c);
  276. #ifndef HTTRACK_DEFLIB
  277. HTSEXT_API char* unescape_http(char* s);
  278. HTSEXT_API char* unescape_http_unharm(char* s, int no_high);
  279. HTSEXT_API char* antislash_unescaped(char* s);
  280. #endif
  281. int ehex(char* s);
  282. char* concat(const char* a,const char* b);
  283. #define copychar(a) concat((a),NULL)
  284. #if HTS_DOSNAME
  285. char* fconcat(char* a,char* b);
  286. char* fconv(char* a);
  287. #else
  288. #define fconv(a) (a)
  289. #define fconcat(a,b) concat(a,b)
  290. #endif
  291. char* fslash(char* a);
  292. char* __fslash(char* a);
  293.  
  294. char* convtolower(char* a);
  295. char* concat(const char* a,const char* b);
  296. void hts_lowcase(char* s);
  297. void hts_replace(char *s,char from,char to);
  298.  
  299. /* Spaces: CR,LF,TAB,FF */
  300. #define  is_space(c)      ( ((c)==' ') || ((c)=='\"') || ((c)==10) || ((c)==13) || ((c)==9) || ((c)==12) || ((c)==11) || ((c)=='\'') )
  301. #define  is_realspace(c)  ( ((c)==' ')                || ((c)==10) || ((c)==13) || ((c)==9) || ((c)==12) || ((c)==11)                )
  302. #define  is_taborspace(c) ( ((c)==' ')                                          || ((c)==9)                             )
  303. #define  is_quote(c)      (               ((c)=='\"')                                                    || ((c)=='\'') )
  304. #define  is_retorsep(c)   (                              ((c)==10) || ((c)==13) || ((c)==9)                                          )
  305. //HTS_INLINE int is_space(char);
  306. //HTS_INLINE int is_realspace(char);
  307.  
  308. void fprintfio(FILE* fp,char* buff,char* prefix);
  309.  
  310. #if HTS_WIN
  311. #else
  312. int sig_ignore_flag( int setflag );     // flag ignore
  313. #endif
  314.  
  315. void cut_path(char* fullpath,char* path,char* pname);
  316. int fexist(char* s);
  317. /*LLint fsize(char* s);    */
  318. INTsys fpsize(FILE* fp);
  319. INTsys fsize(char* s);    
  320. /* root dir */
  321. #ifndef HTTRACK_DEFLIB
  322. HTSEXT_API char* hts_rootdir(char* file);
  323. #endif
  324.  
  325. // Threads
  326. #if USE_PTHREAD
  327. typedef void* ( *beginthread_type )( void * );
  328. unsigned long _beginthread( beginthread_type start_address, unsigned stack_size, void *arglist );
  329. #endif
  330.  
  331. /*
  332. #ifdef __cplusplus
  333. }
  334. #endif
  335. */
  336.  
  337.  
  338.  
  339. /* variables globales */
  340. //extern LLint HTS_TOTAL_RECV;  // flux entrant reτu
  341. //extern int HTS_TOTAL_RECV_STATE;  // status: 0 tout va bien 1: ralentir un peu 2: ralentir 3: beaucoup
  342. extern HTSEXT_API hts_stat_struct HTS_STAT;
  343. extern int _DEBUG_HEAD;
  344. extern FILE* ioinfo;
  345.  
  346. /* constantes */
  347. extern const char* hts_mime_keep[];
  348. extern const char* hts_mime[][2];
  349. extern const char* hts_main_mime[];
  350. extern const char* hts_detect[];
  351. extern const char* hts_detectbeg[];
  352. extern const char* hts_nodetect[];
  353. extern const char* hts_detectURL[];
  354. extern const char* hts_detectandleave[];
  355. extern const char* hts_detect_js[];
  356.  
  357. // defaut wrappers
  358. void  __cdecl htsdefault_init(void);
  359. void  __cdecl htsdefault_uninit(void);
  360. int   __cdecl htsdefault_start(void* opt);
  361. int   __cdecl htsdefault_chopt(void* opt);
  362. int   __cdecl htsdefault_end(void);
  363. int   __cdecl htsdefault_checkhtml(char* html,int len,char* url_adresse,char* url_fichier);
  364. int   __cdecl htsdefault_loop(void* back,int back_max,int back_index,int lien_n,int lien_tot,int stat_time,hts_stat_struct* stats);
  365. char* __cdecl htsdefault_query(char* question);
  366. char* __cdecl htsdefault_query2(char* question);
  367. char* __cdecl htsdefault_query3(char* question);
  368. int   __cdecl htsdefault_check(char* adr,char* fil,int status);
  369. void  __cdecl htsdefault_pause(char* lockfile);
  370. void  __cdecl htsdefault_filesave(char*);
  371. int   __cdecl htsdefault_linkdetected(char* link);
  372. int   __cdecl htsdefault_xfrstatus(void* back);
  373. int   __cdecl htsdefault_savename(char* adr_complete,char* fil_complete,char* referer_adr,char* referer_fil,char* save);
  374. // end defaut wrappers
  375.  
  376. #endif
  377.  
  378.  
  379.